﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace DataAccess
{
	/// <summary>
	/// 数据访问类:ZHZD_T
	/// </summary>
	public partial class ZHZD_T
	{
		public ZHZD_T()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
        public static bool Exists(decimal ZD_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from ZHZD_T");
			strSql.Append(" where ZD_ID=:ZD_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ZD_ID", OracleType.Number,22)};
			parameters[0].Value = ZD_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
        public static bool Add(Model.ZHZD_T model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into ZHZD_T(");
			strSql.Append("ZD_ID,ZD_PARID,ZD_NAME,ZD_CODE,ZD_TYPE)");
			strSql.Append(" values (");
			strSql.Append(":ZD_ID,:ZD_PARID,:ZD_NAME,:ZD_CODE,:ZD_TYPE)");
			OracleParameter[] parameters = {
					new OracleParameter(":ZD_ID", OracleType.Number,10),
					new OracleParameter(":ZD_PARID", OracleType.Number,10),
					new OracleParameter(":ZD_NAME", OracleType.NVarChar),
					new OracleParameter(":ZD_CODE", OracleType.NVarChar),
					new OracleParameter(":ZD_TYPE", OracleType.NVarChar)};
			parameters[0].Value = model.ZD_ID;
			parameters[1].Value = model.ZD_PARID;
			parameters[2].Value = model.ZD_NAME;
			parameters[3].Value = model.ZD_CODE;
			parameters[4].Value = model.ZD_TYPE;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
        public static bool Update(Model.ZHZD_T model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update ZHZD_T set ");
			strSql.Append("ZD_PARID=:ZD_PARID,");
			strSql.Append("ZD_NAME=:ZD_NAME,");
			strSql.Append("ZD_CODE=:ZD_CODE,");
			strSql.Append("ZD_TYPE=:ZD_TYPE");
			strSql.Append(" where ZD_ID=:ZD_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ZD_PARID", OracleType.Number,10),
					new OracleParameter(":ZD_NAME", OracleType.NVarChar),
					new OracleParameter(":ZD_CODE", OracleType.NVarChar),
					new OracleParameter(":ZD_TYPE", OracleType.NVarChar),
					new OracleParameter(":ZD_ID", OracleType.Number,10)};
			parameters[0].Value = model.ZD_PARID;
			parameters[1].Value = model.ZD_NAME;
			parameters[2].Value = model.ZD_CODE;
			parameters[3].Value = model.ZD_TYPE;
			parameters[4].Value = model.ZD_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
        public static bool Delete(decimal ZD_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ZHZD_T ");
			strSql.Append(" where ZD_ID=:ZD_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ZD_ID", OracleType.Number,22)};
			parameters[0].Value = ZD_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
        public static bool DeleteList(string ZD_IDlist)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ZHZD_T ");
			strSql.Append(" where ZD_ID in ("+ZD_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public static Model.ZHZD_T GetModel(decimal ZD_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ZD_ID,ZD_PARID,ZD_NAME,ZD_CODE,ZD_TYPE from ZHZD_T ");
			strSql.Append(" where ZD_ID=:ZD_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ZD_ID", OracleType.Number,22)};
			parameters[0].Value = ZD_ID;

			Model.ZHZD_T model=new Model.ZHZD_T();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ZD_ID"]!=null && ds.Tables[0].Rows[0]["ZD_ID"].ToString()!="")
				{
					model.ZD_ID=decimal.Parse(ds.Tables[0].Rows[0]["ZD_ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ZD_PARID"]!=null && ds.Tables[0].Rows[0]["ZD_PARID"].ToString()!="")
				{
					model.ZD_PARID=decimal.Parse(ds.Tables[0].Rows[0]["ZD_PARID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ZD_NAME"]!=null && ds.Tables[0].Rows[0]["ZD_NAME"].ToString()!="")
				{
					model.ZD_NAME=ds.Tables[0].Rows[0]["ZD_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ZD_CODE"]!=null && ds.Tables[0].Rows[0]["ZD_CODE"].ToString()!="")
				{
					model.ZD_CODE=ds.Tables[0].Rows[0]["ZD_CODE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ZD_TYPE"]!=null && ds.Tables[0].Rows[0]["ZD_TYPE"].ToString()!="")
				{
					model.ZD_TYPE=ds.Tables[0].Rows[0]["ZD_TYPE"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
        public static DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ZD_ID,ZD_PARID,ZD_NAME,ZD_CODE,ZD_TYPE ");
			strSql.Append(" FROM ZHZD_T ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "ZHZD_T";
			parameters[1].Value = "ZD_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

